<template>
  <view class="content">
    <view class="text-area">
      <icon type="success" size="26" />
      <icon type="success" size="26" />
	  {{ sniper }}
    </view>
  </view>
</template>

<script>
  import { login, getUserInfo, studentInfo, userByWxCode } from '@/api/login/index';
  import { serializeToUrl } from '@common/utils'
  import { mapGetters, mapMutations } from 'vuex';
  export default {
    data() {
      return {
        title: 'Hello',
        appId: 'wxd0b90fdf369aeca3',
        code: ''
      };
    },
	computed: {
		...mapGetters(['sniper'])
	},
    onLoad(option) {
	  // this.getWxUserCode();
    },
    onPullDownRefresh() {
      var app = getCurrentPages();
      console.log('app', app[0].route);
    },
    methods: {
	  ...mapMutations(['setSniper']),
	  vuexTest() {
		this.setSniper('777');
	  },
      loginT() {
        var data = {
          placeId: '3098',
          password: 'test123456',
          username: 'cy'
        };
        login(data).then(({ success, msg, data }) => {
          if (!success)
            return uni.showToast({
              icon: 'success',
              title: msg,
              mask: true
            });
          uni.setStorageSync('token', data.token);
          uni.setStorageSync('placeId', '3098');
          this.getUserInfoT();
          this.loadStudents();
        });
      },
      getWxUserCode() {
		  uni.login({
			  provider: 'weixin',
			  success: (r) => {
				  console.log(r);
				  const param = {
					  code: r.code,
					  placeId: '3098'
				  }
				  userByWxCode(param).then((rsp) => {
					  console.log(rsp);
				  })
			  }
		  })
        // if (this.code) return;
        //    const redirect = {
        //      param: {
        //        appId: this.appId,
        //        redirect_uri: encodeURIComponent(getCurrentPages()[0].route),
        //        response_type: 'code',
        //        scope: 'snsapi_userinfo',
        //        state: '0'
        //      },
        //      url: 'https://open.weixin.qq.com/connect/oauth2/authorize',
        //      hash: '#wechat_redirect'
        //    };
		   // console.log(redirect)
           // const redirectParam = serializeToUrl(redirect.param, false);
           // const redirectUrl = `${redirect.url}?${redirectParam}${redirect.hash}`;
           // 获取用户code
		   // console.log(redirectParam)
           // uni.navigateTo(redirect.url);
      },
      getUserInfoT() {
        getUserInfo().then(({ success, msg, data }) => {
          console.log(success, msg, data);
        });
      },
      loadStudents() {
        studentInfo().then(({ success, msg, data }) => {
          // console.log(success, msg, data);
        });
      }
    }
  };
</script>

<style lang="scss">
  .content {
    display: flex;
    width: 100vw;
    height: 100vh;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .logo {
    width: 200rpx;
    height: 200rpx;
    margin-top: 200rpx;
    margin-right: auto;
    margin-bottom: 50rpx;
    margin-left: auto;
  }

  .text-area {
    display: flex;
    width: 100vw;
    height: 50vh;
    background-size: 100% 100%;
    justify-content: center;
  }

  .title {
    font-size: 36rpx;
    color: #8f8f94;
  }

  .less {
    &__test {
      color: white;
    }
  }
</style>
